package org.example.demos.suanfati;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ListOverlap<T> {

    public static void main(String[] args) {
        Integer[] arr1 = new Integer[]{1,1,1};
        Integer[] arr2 = new Integer[]{1};
        List<Integer> arrayList = Arrays.asList(arr1);
        List<Integer> array2List = Arrays.asList(arr2);
        ListOverlap<Integer> test = new ListOverlap<>();
        System.out.println(test.getOverlap(arrayList, array2List));
        List<Integer> collect = arrayList.stream().distinct().collect(Collectors.toList());
        System.out.println(collect);
    }

    private List<T> getOverlap(List<T> list1, List<T> list2){
        List<T> res = new ArrayList<>(list1);
        res.retainAll(list2);
        return res;
    }
}
